#include "MoleculeReader.h"

#include "../model/Atom.h"
#include "../model/Atom_Element.h"
#include "../model/Molecule_Visitor.h"
#include "../model/Molecule.h"
#include "PDB_Types_Adapter.h"


/**
 * Have a PDB adapter do the hard work of reading the PDB,
 * we'll limit ourselves to have a callback available to
 * do something with the just-ready atom.
 */
void MoleculeReader::read(PDB_Types_Adapter& pdb, Molecule* molecule)
{
    this->molecule = molecule;

    Molecule_Visitor& add_to_molecule = *this;
    pdb.for_each_atom(add_to_molecule);
    // Notify the molecule we just finished reading the last fragment.
    // TODO: Find a better way
    this->molecule->on_fragment_change();
}

/**
 * New atom found; add it to the dictionary
 */
void MoleculeReader::on_atom_found(const Atom* atom, const Atom_Element* type)
{
    this->molecule->add(*atom, *type);
}

#include <iostream>
void MoleculeReader::on_fragment_start()
{
    this->molecule->on_fragment_change();
}


